
const timeoutMap:Record<string,number> = {};
// 延时操作，如果key存在，调用时清除对应key之前的延时操作
export const  delay = (callback:Function, ms:string|number = 100, key?:string) => {
	const timeout = setTimeout(callback, Number(ms));
	if (!!key) {
		timeoutMap[key] && clearTimeout(timeoutMap[key]);
		timeoutMap[key] = timeout;
	}
	return timeout;
}
export type Touch = {
	clientX:number,
	clientY:number
}
// 获取最终的touch位置
export const  getTouch = (e:{touches?:Array<Touch>,changedTouches?:Array<Touch>,datail?:Touch}) => {
	let touch:Touch;
	if (e.touches && e.touches.length) {
		touch = e.touches[0];
	} else if (e.changedTouches && e.changedTouches.length) {
		touch = e.changedTouches[0];
	} else if (e.datail && Object.keys(e.datail).length) {
		touch = e.datail;
	} else {
		return {touchX: 0, touchY: 0}
	}
	return {
		touchX: touch.clientX,
		touchY: touch.clientY
	};
}